<%@ page language="java" contentType="text/html; charset=utf8"
    pageEncoding="utf8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf8">
<!-- 引入easyui的样式 -->
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/themes/bootstrap/easyui.css">   
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/themes/icon.css">
<!-- 引入Js -->
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/easyui-lang-zh_CN.js"></script>

<title>车俩管理</title>
</head>
<script type="text/javascript">
//打开增加车辆窗口
function newVan(){
	$('#add').window('open');
};
//编辑车辆窗口重置
function clearUpdateForm(){
	$('#updateform').form('clear');
};
//增加窗口表单重置
function clearForm(){
	$('#addform').form('clear');
};
//增加窗口提交表单
function submitForm(){
	var car_type=$('#car_typeadd').val();
	if(car_type==""){
		$.messager.alert('提示','请输入');
		return false;
	}
	$('#addform').form('submit',{
		 success:function(data){
			 
			 if(data == "false"){  
	                $.messager.alert('提示','添加失败');
	                }else{  
	                $.messager.alert('提示','添加成功','info',function(){  
	                	$('#add').window('close');
	                	$("#dg").datagrid('reload');
	                });
	                }  
		    }
	});	
}
//编辑车辆窗口打开
function editVan(){
	var data = $("#dg").datagrid('getSelections');	
	if(data.length==0){
		$.messager.show({
			title:'警告',
			msg:'请选中需要修改的数据',
			timeout:1500,
			showType:'slide',
				style:{
					left:100,
					right:'',
					top:100
				}
	  		});
	}else if(data.length!=1){
		$.messager.show({
			title:'警告',
			msg:'你只能选择一条数据修改',
			timeout:1500,
			showType:'slide',
				style:{
					left:100,
					right:'',
					top:100
				}
	  		});
	}else{
		$('#update').window('open');
	}	
}	
function updateForm(){
	var id = $("#dg").datagrid('getSelected').id;
	$('#updateform').form('submit',{
	    onSubmit: function(param){
			param.id = id;
	    }, 
		success:function(data){ 
		 if(data == "false"){  
               $.messager.alert('提示','编辑失败');
               }else{  
               $.messager.alert('提示','编辑成功','info',function(){  
               	$('#update').window('close');
               	$("#dg").datagrid('reload');
               });
               }  
	    }
	});
} 
//删除车辆
function destroyVan() {
	var data=$("#dg").datagrid('getSelections');
    if(data.length==0){
    	$.messager.show({
    		title:'警告',
    		msg:'请选择你要删除的数据',
    		timeout:1000,
    		showType:'slide',
    		style:{
    			left:50,
    			right:'',
    			top:100
    		}
    	});
                }else {
		//声明一个数组wid
		var ids=[];
		for (var i = 0; i < data.length; i++) {
			ids.push(data[i].id)
		}
		$.messager.confirm('提示', '确认是否删除这'+data.length+'条数据？', function(r){
			if (r){
			    $.ajax({
			    	type:"post",
			    	url:"${pageContext.request.contextPath}/showvan/destroyvan_destroyVan.do",
			    	data:{"ids":ids.join(",")},
			    	dataType:"text",
			    	success:function(data){
			    		$.messager.alert('提示','删除成功','info',function(){
    		    		$("#dg").datagrid('reload');
    		    		$("#dg").datagrid('uncheckAll');
    		    });
			    	}
			    });
			}else {
				$("#dg"),datagrid("uncheckAll");
			}
		});
	}
}

</script>
<body>
	<table id="dg" title="Van" class="easyui-datagrid" 
			url="${pageContext.request.contextPath}/showvan/showvan_showVan.do"
    		pagination="true"
    		toolbar="#toolbar"
    		fit="true"
    		rownumbers="true" fitColumns="true" >
    	<thead>
    		<tr>
    			<th field="ck" checkbox="true" width="50"></th>
    			<th field="id" width="50" hidden="true"></th>
    			<th field="car_type" width="50">车型</th>
    			<th field="name" width="50">司机</th>
    			<th field="car_status" width="50">车辆状态</th>
    		</tr>
    	</thead>
    </table>
    <div id="toolbar">
    	<a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newVan()">添加车辆</a>
    	<a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editVan()">编辑车辆</a>
    	<a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="destroyVan()">删除车辆</a>
    </div>
    <!-- 增加功能面板 -->
    <div style="margin:20px 0;"></div>
	<div id="add" class="easyui-window" title="添加车辆" style="width:400px" closed="true" modal="true">
		<div style="padding:10px 60px 20px 60px">
	    <form id="addform" method="post" action="${pageContext.request.contextPath}/showvan/addvan_addVan.do">
	    	<table cellpadding="5">
	    		<tr>
	    			<td>车型:</td>
	    			<td><input id="car_typeadd" class="easyui-textbox" type="text" name="car_type" data-options="required:true"></input></td>
	    		</tr>
	    		<tr>
	    			<td>车辆状态:</td>
	    			<td>
	    				<select id="car_statusadd" class="easyui-combobox" name="car_status" editable="editable"><option value="0">空闲</option><option value="1">非空闲</option></select>
	    			</td>
	    		</tr>
	    	</table>
	    </form>
	    <div style="text-align:center;padding:5px">
	    	<a href="javascript:void(0)" class="easyui-linkbutton" onclick="submitForm()">提交</a>
	    	<a href="javascript:void(0)" class="easyui-linkbutton" onclick="clearForm()">重置</a>
	    </div>
	    </div>
	</div>
	<!-- 编辑车辆 -->
	<div style="margin:20px 0;"></div>
	<div id="update" class="easyui-window" title="编辑车辆" style="width:400px" closed="true" modal="true">
		<div style="padding:10px 60px 20px 60px">
	    <form id="updateform" method="post" action="${pageContext.request.contextPath}/showvan/updatevan_updateVan.do">
	    	<table cellpadding="5">
	    		<tr>
	    			<td>车型:</td>
	    			<td><input  class="easyui-textbox" type="text" name="car_type" data-options="required:true"></input></td>
	    		</tr>
	    		<tr>
	    			<td>车辆状态:</td>
	    			<td>
	    				<select id="car_status" class="easyui-combobox" name="car_status" editable="editable"><option value="0">空闲</option><option value="1">非空闲</option></select>
	    			</td>
	    		</tr>
	    	</table>
	    </form>
	    <div style="text-align:center;padding:5px">
	    	<a href="javascript:void(0)" class="easyui-linkbutton" onclick="updateForm()">提交</a>
	    	<a href="javascript:void(0)" class="easyui-linkbutton" onclick="clearUpdateForm()">重置</a>
	    </div>
	    </div>
	</div>
</body>
</html>